package configuration

import (
	"fmt"
	"github.com/caarlos0/env/v6"
	"time"
	"v8s/logger"
)

type (
	Properties struct {
		Log logger.Properties `envPrefix:"LOG_"`

		Mongo MongoProperties `envPrefix:"MONGO_"`

		StatusController SchedulerProperties `envPrefix:"STATUS_"`
	}

	MongoProperties struct {
		ConnectionURI string `env:"CONNECTION_URI"`
		Database      string `env:"DATABASE,notEmpty"`
	}

	SchedulerProperties struct {
		Timeout              time.Duration `env:"TIMEOUT" envDefault:"1m"`
		TaskExecutionTimeout time.Duration `env:"TASK_EXECUTION_TIMEOUT" envDefault:"30m"`
	}
)

func ReadProperties() *Properties {
	config := &Properties{}

	if err := env.Parse(config); err != nil {
		panic(fmt.Errorf("read config error: %w", err))
	}

	fmt.Printf("config: %+v", config)
	return config
}
